package com.services.aidl;

import android.os.Parcel;
import android.os.Parcelable;

public class Queue implements Parcelable {

	private int id;					//队列id
	private String name;			//显示在进度条上的文字
	private String url;				//下载的URL地址，必须是一个标准url地址
	private String savePath;		//保存到sdcard的路径，必须是一个完整路径
	private String downingIntent;	//下载过程会在status bar生成一个notify，
									//点击notify会跳转到该intent指向的Activity。其实质是一个action字符串，如：com.obatu.client.QueueList
	private String completeIntent;  //下载完成后点击notify跳转到的Activity，同上解释
	private long fileLength = 0;	//文件总长度，该字段会在开始下载的时候写入
	private long downSize = 0;		//已经下载的字节数
	private boolean cancel = false;	//是否已经取消该队列，用于控制取消下载
	private boolean autoRun = false;//下载完成后，是否自动执行completeIntent

    //必须提供一个名为CREATOR的static final属性 该属性需要实现android.os.Parcelable.Creator<T>接口
    public static final Parcelable.Creator<Queue> CREATOR = new Parcelable.Creator<Queue>() {  

        @Override
        public Queue createFromParcel(Parcel source) {
            return new Queue(source);
        }  

        @Override
        public Queue[] newArray(int size) {
            return new Queue[size];
        }
    };  

	public Queue() {

	}

	private Queue(Parcel source){
		readFromParcel(source);
	}

	public void readFromParcel(Parcel source) {
		 id = source.readInt();
		 name = source.readString();
		 url = source.readString();
		 savePath = source.readString();
		 downingIntent = source.readString();
		 completeIntent = source.readString();
		 fileLength = source.readLong();
		 downSize = source.readLong();
		 boolean[] b = new boolean[2];
		 source.readBooleanArray(b);
		 if(b.length > 0){
			 cancel = b[0];
			 autoRun = b[1];
		 }
	}

	@Override
	public int describeContents() {
		return 0;
	}

	@Override
	public void writeToParcel(Parcel dest, int flag) {
		dest.writeInt(id);
		dest.writeString(name);
		dest.writeString(url);
		dest.writeString(savePath);
		dest.writeString(downingIntent);
		dest.writeString(completeIntent);
		dest.writeLong(fileLength);
		dest.writeLong(downSize);
		boolean[] b = {cancel,autoRun};
		dest.writeBooleanArray(b);
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getSavePath() {
		return savePath;
	}

	public void setSavePath(String savePath) {
		this.savePath = savePath;
	}

	public String getDowningIntent() {
		return downingIntent;
	}

	public void setDowningIntent(String downingIntent) {
		this.downingIntent = downingIntent;
	}

	public String getCompleteIntent() {
		return completeIntent;
	}

	public void setCompleteIntent(String completeIntent) {
		this.completeIntent = completeIntent;
	}

	public long getFileLength() {
		return fileLength;
	}

	public void setFileLength(long fileLength) {
		this.fileLength = fileLength;
	}

	public long getDownSize() {
		return downSize;
	}

	public void setDownSize(long downSize) {
		this.downSize = downSize;
	}

	public boolean isCancel() {
		return cancel;
	}

	public void setCancel(boolean cancel) {
		this.cancel = cancel;
	}

	public boolean isAutoRun() {
		return autoRun;
	}

	public void setAutoRun(boolean autoRun) {
		this.autoRun = autoRun;
	}

}